<?php include_once('header.php');?>
	<div class="main-content">
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
			</script>
			<ul class="breadcrumb">
				<li>
					<i class="icon-home home-icon"></i>
					供位管理
				</li>
				<li>
					供位列表
				</li>
			</ul>
		</div>
		<div class="page-content">
			<div class="page-header">
				<h1 class="blue"><i class="icon-edit"></i> 添加供位</h1>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<form class="form-horizontal" enctype="multipart/form-data" role="form" method="post" onkeydown="if(event.keyCode==13){return false;}" action="/admin/fora/edit"  onsubmit="return check()">
						<input type="hidden" class="form-control" name="id" id="id" value="<?php echo $data['id'];?>">
                                                <div class="form-group">
							<label for="title" class="col-sm-1 control-label">供区名称:</label>
							<div class="col-sm-6">
                                                            <input type="text" class="form-control" name="name" id="name" value="<?php echo $data['name'];?>">
															
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">供区编码:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" id="code" name="code"   value="<?php echo $data['code'];?>">
							</div>
						</div>													
						<div class="form-group">
							<label  class="col-sm-1 control-label">数量:</label>
							<div class="col-sm-4">
								<input type="number" class="form-control" id="num" name="num" value="<?php echo $data['num'];?>">
							</div>
						</div>
						<div class="form-group">
							<label  class="col-sm-1 control-label">状态:</label>
							<div class="col-sm-4">
								<label>
									<input type="radio" name="status" <?php if($data['status']==1)echo 'checked';?> value="1" >未售</input>
									<input type="radio" name="status"  <?php if($data['status']==2)echo 'checked';?> value="2">已售</input>
									<input type="radio" name="status"  <?php if($data['status']==3)echo 'checked';?> value="3">锁定</input>
								</label>
							</div>
						</div>
					 	<div class="form-group">
					   		<div class="col-sm-offset-1 col-sm-10">
								<button type="submit" id="submit" class="btn btn-primary">确定</button>

								<button type="submit" id="cancel" class="btn btn-primary">取消</button>
							</div>
					  	</div>
					</form>	
				</div>
			</div>					
		</div>													
	</div>
<?php include_once('content.php');?>
	<link href="/public_source/www/assets/css/ace.min.css" rel="stylesheet" />	
	<link href="/public_source/www/assets/css/jquery.tag-editor.css" rel="stylesheet"/>
	<link  rel="stylesheet" href="/public_source/www/assets/css/jquery-confirm.css" />
	<link  rel="stylesheet" href="/public_source/www/css/confirm.css" />
	<script src="/public_source/www/assets/js/jquery.dataTables.min.js"></script>
	<script src="/public_source/www/assets/js/jquery.dataTables.bootstrap.js"></script>
        <script src="/public_source/www/assets/js/jquery-confirm.js"></script>
		
		
    <script src="/public_source/www/assets/js/bootbox.min.js"></script>  
	<script src="/public_source/www/assets/js/jquery.tag-editor.min.js"></script>
	<script src="/public_source/www/js/areas.js"></script>
	<script src="/public_source/www/My97DatePicker/WdatePicker.js"></script> 
<?php include_once('footer.php');?>	
<script type="text/javascript">
	$(document).ready(function(){
		$("#cancel").click(function() {
			window.location.replace('/admin/fora/fora_index');
			return false;
		});
	});
	function xietruename(){
               if( check_name()){
                   var username = document.getElementById("username").value;
                    $("#true_name").val(username);
               }else{
                   $("#username").val('');
               }
		
	}
	function check() {
	   var name = document.getElementById("name").value;
	   var code = document.getElementById("code").value;
	   var num = document.getElementById("num").value;
		var old_num =<?php echo $data['num'];?>;
		var id='<?php echo $data['id'];?>';
		if(name ==  null || name == '') {
	        $.alert({
                title: '提示',
                content: '供区名称不能为空',
                confirm: function(){
                    
                }
            });
	        return false;
	   }
		if(code ==  null || code == '') {
			$.alert({
				title: '提示',
				content: '供区编码不能为空',
				confirm: function(){

				}
			});
			return false;
		}
		if(num ==  null || num == '') {
			$.alert({
				title: '提示',
				content: '数量不能为空',
				confirm: function(){

				}
			});
			return false;
		}
		if(num < old_num) {
			$.alert({
				title: '提示',
				content: '修改数量不能小于原有数量',
				confirm: function(){

				}
			});
			return false;
		}
		var data = {'id':id,key:'name','value':name};
		$.ajax({
			url:"/admin/fora/check_sole",
			async: false,
			type:"post",
			data: data,
			dataType: 'json',
			success:function(data) {
				bool = data;
			}
		});
		if(!bool) {
			$.alert({
				title: '提示',
				content:'供区名称已存在',
				confirm: function(){
				}
			});
			return false;
		}
		var data = {'id':id,key:'code','value':code};
		$.ajax({
			url:"/admin/fora/check_sole",
			async: false,
			type:"post",
			data: data,
			dataType: 'json',
			success:function(data) {
				bool = data;
			}
		});
		if(!bool) {
			$.alert({
				title: '提示',
				content:'供区编码已存在',
				confirm: function(){
				}
			});
			return false;
		}
	   return true;
	}

</script>		